<template>
  <el-dropdown @command="changeLocale">
    <div class="icon-warp">
      <i class="iconfont icon-yuyan font-style" />
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item command="zh">
          中文
        </el-dropdown-item>
        <el-dropdown-item command="en">
          En
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts">
import { defineComponent, getCurrentInstance } from 'vue';
import { storage } from '@/utils/index';
export default defineComponent({
  name: 'Language',
  setup() {
    const { proxy } = getCurrentInstance();
    function changeLocale(type: string) {
      proxy.$i18n.locale = type;
      storage.setLocal('language', type);

      //刷新页面 切换element-plus语言 框架没有提供修改语言api
      location.reload();
    }
    return {
      changeLocale,
    };
  },
});
</script>

<style lang="scss" scoped>
.icon-warp {
  width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.font-style {
  color: var(--laout-header-color);
  font-size: 16px;
  cursor: pointer;
  transition: 0.2s;
}
</style>